package org.casper.gc;

import java.util.HashSet;
import java.util.Set;

public class Test {
	
	/**
	 * 内存泄漏简单实例:当集合属性元素被修改后
	 */
	public static void main(String[] args) {
		Set<User> userSet= new HashSet<>();
		User u1 = new User("123","张无忌","321");
		User u2 = new User("234","张翠山","432");
		User u3 = new User("345","张三丰","543");
		userSet.add(u1);
		userSet.add(u2);
		userSet.add(u3);
		//修改u2对象的id属性,?集合中u2对象的值?
		u2.setId("666");
		//从集合中移除u2对象,?u2对象是否被移除?
		userSet.remove(u2);
		//从新添加u2对象,?此时集合中的元素的个数?
		userSet.add(u2);
		for (User user : userSet) {
			System.err.println(user);
		}
	}
}
